<template>
  <div class="dateSorting">
    <div v-for="(v,k) of datesorting" :key="v.id" class="box">
        <h1 class="yeas" v-if="k===0">{{ yeas(k,v) }}</h1>
        <h2 class="month" v-if="month(k,v)">{{month(k,v)}}</h2>
        <h3 class="day" v-if="day(k,v)">{{day(k,v)}}</h3>
      <article-item
        :itemData="v"
        style="width: 369px"
        class="item"
      ></article-item>
      
    </div>
  </div>
</template>
<script>
import articleItem from "components/common/blogArticle/ArticleItem.vue";


export default {
  name: "dateSorting",
  props:{
      datesorting:{
          type:Array,
          default(){
              return []
          }
      }
  },
  data() {
    return {
      index: 0,
    };
  },
  components: { articleItem },
  methods: {
    yeas(k,v){
        if(k===0)return v.time.slice(0,4);
        
    },
    month(k){
        var tow
        var one = this.datesorting[k].time.slice(5,7);
        if(this.datesorting[k-1]){
            tow = this.datesorting[k-1].time.slice(5,7);
        }
       
        if(one!==tow){
            return one;
        }
    },
    day(k){
        var tow
        var one = this.datesorting[k].time.slice(8,10);
        if(this.datesorting[k-1]){
            tow = this.datesorting[k-1].time.slice(8,10);
        }
       
        if(one!==tow){
            return one;
        }
    }
  },
};
</script>
<style scoped>
* {
  margin: 0px;
  padding: 0px;
}
.dateSorting {
  width: 800px;
  margin: 0 auto;
  margin-top:70px ;
  position: relative;
}
.dateSorting::before{
    content: "";
    display: block;
    position: absolute;
    left: 50%;
    transform: translate(-50%, 0%);
    width: 10px;
    height: 100%;
    background: skyblue;
}
.box {
  position: relative;
  margin-top: -20px;
}
.box:nth-child(2n) .item{
    position: relative;
    margin: 0px;
    bottom: 0;
    left: 430px;
}
.box:nth-child(2n-1) .item{
  position: relative;
    bottom: 0;
    right: 0;
}
.yeas{
    width: 130px;
    height: 130px;
    margin: 0 auto;
    margin-bottom:70px;
    text-align: center;
    line-height: 130px;
    border-radius:50% ;
    background: pink;
    color: #fff;
    margin-bottom:70px ;
}
.day{
    width: 50px;
    height: 50px;
    margin: 0 auto;
    margin-bottom: 35px;
    text-align: center;
    line-height: 50px;
    border-radius:50% ;
    background: pink;
    color: #fff;
}
.month{
    width: 100px;
    height: 100px;
    margin: 0 auto;
     margin-bottom: 55px;
    text-align: center;
    line-height: 100px;
    border-radius:50% ;
    background: pink;
    color: #fff;
}
</style>